package com.singzi.leetcode.jianzhiOffer2;

import java.util.List;
import java.util.TreeSet;

public class T0035 {
}
class Solution0035 {
    public int findMinDifference(List<String> timePoints) {

        TreeSet<Integer> set = new TreeSet<>();
        int ans = Integer.MAX_VALUE;
        int min = Integer.MIN_VALUE;
        for(String timePoint:timePoints){
            int hour = Integer.parseInt(timePoint.split(":")[0]);
            int minute = Integer.parseInt(timePoint.split(":")[1]);
            minute += hour*60;
            if(set.contains(minute)) return 0;
            else {
                if(set.ceiling(minute)!=null) min = Math.min(min, set.ceiling(minute) - minute);
                if(set.floor(minute)!=null) min = Math.min(min, -set.floor(minute) + minute);
                ans = Math.min(min, ans);
                set.add(minute);
                set.add(minute + 24*60);

            }

        }
        return  ans;

    }
}